home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
environ
/
setvar.asm
< prev
Wrap
Assembly Source File
|
1985-09-15
|
4KB
|
168 lines
PAGE 58,132
; FILE: SETVAR.ASM
;
; THIS FILE WAS PRODUCED BY RE-CONSTITUTING AN EXE FILE
; DOWNLOADED FROM THE CLM BBS
;
; SETVAR WAITS FOR THE USER TO INPUT A STRING, AND STORES
; IT IN THE STRING ENVIRONMENT UNDER A NAME SPECIFIED ON THE
; COMMAND LINE.
;
CODE SEGMENT BYTE PUBLIC
ASSUME CS:CODE,DS:CODE
;DEFINE SOME SYMBOLS IN THE PSP
ORG 014H
PARPSP DW ?
ORG 080H
LENTH DB ?
COMLINE DB ?
ORG 0100H
START: JMP REAL_START
;DATA IS STORED HERE
ENVSIZE DW 0
NAMELEN DW 0
BUFFER DB 07FH ;BUFFER FOR SENDING TO BUFFER KEYBOARD SYSCALL
CHARS DB 0 ;ACTUAL NUMBER OF CHARACTERS TYPED
DB 07FH DUP ( 0 ) ;THE STRING DATA IS STORED HERE.
;CODE STARTS HERE
REAL_START:
MOV BX,WORD PTR LENTH ;GET LENGTH OF COMMAND STRING
XOR BH,BH
CMP BX,1 ;MUST BE GREATER THAN 1.
JG IS_NAME ;IF NOT, THEY FORGOT TO SPECIFY
JMP EXIT ;THE STRING NAME, SO EXIT.
IS_NAME: ;L0196:
MOV NAMELEN,BX
MOV BYTE PTR [BX+0081H],03DH ;STORE AN = AT END OF NAME
MOV DX,PARPSP ;GET THE CALLING PROGRAMS PSP SEG
MOV ES,DX ;PUT IT IN ES
MOV BX,WORD PTR ES:[002CH] ;GET THE CALLERS ENVIRONMENT STRING
CMP BX,0 ;IF IT IS ZERO,
JNZ L01BC ;
MOV BX,DX ;THEN USE THE PSP ADDRESS
DEC BX ;MINUS 16 (IT'S A SEGMENT VALUE)
MOV ES,BX ;AS THE ADDRESS OF A PLACE TO
ADD BX,WORD PTR ES:[0003] ;FETCH THE ADDRESS OF AN ENVIRONMENT
ADD BX,2 ;STRING! (I DON'T GET THIS?!...MFH)
L01BC:
MOV DX,BX ;PUT ENVIRONMENT STRING ADDRESS IN DX
DEC DX ;BACKUP 16 BYTES FROM THAT,
MOV ES,DX ;USE THAT AS AN ADDRESS OF A PLACE TO
MOV CX,WORD PTR ES:[0003] ;FETCH THE ADDRESS OF THE ENVIRONMENT SIZE?
SHL CX,1 ;MULTIPLY THAT BY 16
SHL CX,1 ;TO GET THE ENVIRONMENT STRING SIZE.
SHL CX,1
SHL CX,1
MOV ENVSIZE,CX ;AND STORE IT AWAY.
MOV ES,BX ;PUT ENVIRONMENT SEG IN ES.
SUB DI,DI ;INITIALIZE DI AND BX TO ZERO
MOV BX,DI
MOV DX,CX ;INITIALIZE CX TO THE ENVIRONMENT SIZE
L01DA:
CMP DI,ENVSIZE
JNB L022B ;
MOV AL,03DH
CALL S0295 ;
JNZ L022B ;
MOV BX,DI
MOV DX,CX
DEC DI
MOV CX,NAMELEN
MOV SI,0081H
ADD SI,NAMELEN
STD
REPZ CMPSB
JNZ L01DA ;
INC DI
MOV BX,DI
MOV AL,0
ADD DX,NAMELEN
CALL S0295 ;
CMP AL,ES:[DI]
JNZ L0216 ;
MOV DI,BX
MOV BYTE PTR ES:[DI],00
JMP L022B ;
L0216:
MOV SI,DI
MOV CX,ENVSIZE
SUB CX,DI
MOV AX,ES
MOV DS,AX
MOV DI,BX
CLD
REPZ MOVSB
MOV AX,CS
MOV DS,AX
L022B:
SUB DI,DI
MOV CX,ENVSIZE
MOV AX,0
L0234:
CMP AX,ES:[DI]
JZ L023F ;
INC DI
LOOP L0234 ;
JMP EXIT ;
L023F:
INC DI
MOV BX,ENVSIZE ;GET SIZE REMAINING ENVIRONMENT
SUB BX,DI
SUB BX,NAMELEN ;SUBTRACT SIZE OF NAME,
JLE EXIT ;QUIT IF NOT ENUF ROOM.
SUB BX,2 ;LEAVE ROOM FOR 2 NULS,
JLE EXIT ;QUIT IF DROPS BELOW ZERO.
CMP BX,07FH ;LIMIT THE SIZE IF THE STRING
JLE NO_LIMIT ;TO 7F BYTES.
MOV BX,007FH
NO_LIMIT: ;L0259:
MOV DX,OFFSET BUFFER ;GET ADDRESS OF MSDOS REQUIRED
MOV SI,DX ;BUFFER
MOV [SI],BL ;STORE MAX STRING SIZE
MOV AH,0AH
INT 21H ;BUFFERED KEYBOARD INPUT INTERUPT
MOV DL,0AH ;ECHO A CARRAGE RETURN
MOV AH,02 ;AFTER GETTING A STRING
INT 21H ;FROM THE USER
XOR CH,CH
MOV CL,[SI+01]
CMP CL,0
JZ EXIT ;
INC SI
INC SI
MOV BX,SI
MOV DX,CX
MOV CX,NAMELEN
MOV SI,0082H
CLD
REPZ MOVSB
MOV SI,BX
MOV CX,DX
REPZ MOVSB
MOV AX,0
STOSW
EXIT:
MOV AH,04CH ;EXIT WITH STATUS CALL, STATUS IS THE
MOV AL,CHARS ;NUMBER OF CHARS ENTERED BY USER.
INT 21H ;RETURN THAT AS YOUR EXIT VALUE.
S0295:
MOV DI,BX
MOV CX,DX
CLD
REPNZ SCASB
RET
CODE ENDS
END START